package com.design.designmode.struct.combine;

import java.util.List;

/**
 * @author hxl
 * @since 2023-04-17
 */
public class Main {

    static void print(Component root) {
        // 广度遍历
        root.printName();
        List<Component> children = root.getChildren();
        if (children == null) return;
        for (Component child : children) {
            print(child);
        }
    }


    public static void main(String[] args) {
        Component root = new Composite("root");


        Component level1 = new Composite("level1");
        Component level2 = new Composite("level2");


        Component leaf1 = new Leaf("leaf1");
        Component leaf2 = new Leaf("leaf2");
        Component leaf3 = new Leaf("leaf3");
        Component leaf4 = new Leaf("leaf4");


        root.add(level1);
        root.add(level2);
        root.add(leaf1);

        level1.add(leaf2);
        level1.add(leaf3);

        print(root);

    }
}
